package com.hucheng.seckill.vo;

import com.hucheng.seckill.entity.OrderItemDO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 返回界面数据
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrderItemVO implements Serializable{
    private Integer itemId;
    private Integer orderId;
    private String orderItemNumber;
    private Integer status;
    private Integer formatId;
    private Integer userId;
    private String goodsName;
    private Integer goodsNumber;
    private BigDecimal goodsPrice;
    private BigDecimal goodsAmount;
    private Integer isDel;
    private String dateCreated;
    private String dateUpdated;

    public static OrderItemVO buildOrderItemVO(final OrderItemDO orderItemDO) {
        if (orderItemDO == null) {
            return null;
        }
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return new OrderItemVO(orderItemDO.getItemId(),orderItemDO.getOrderId(),orderItemDO.getOrderItemNumber(),
                orderItemDO.getStatus(),orderItemDO.getFormatId(),orderItemDO.getUserId(),orderItemDO.getGoodsName(),
                orderItemDO.getGoodsNumber(),orderItemDO.getGoodsPrice(),orderItemDO.getGoodsAmount(),orderItemDO.getIsDel(),
                dateTimeFormatter.format(orderItemDO.getDateCreated().toLocalDateTime()),
                dateTimeFormatter.format(orderItemDO.getDateUpdated().toLocalDateTime()));
    }
}
